<template>
	<view class="dydetail">
		<u-navbar title="详情" :border-bottom="false" back-icon-color="#ffffff" title-color="#fff" :background="{backgroundColor:'#2A2931'}"></u-navbar>
		<view class="detail">
			<view class="top">
				<view class="avatar">
					<u-avatar size="mini" show-sex :sex-icon="detail.sex == '男' ? 'man' : 'woman'" :src="HOSTURL + detail.head_100"></u-avatar>
				</view>
				<view class="info">
					<view class="nickname">
						<text>{{detail.name}}</text>
				<!-- 		<image src="../../static/girl.png" class="ptag"></image>
						<image src="../../static/real.png" class="ptag"></image> -->
					</view>
					<view class="pubtime">
						{{detail.addtime}}
					</view>
					<view class="middle">
						<view class="tag" v-if="detail.content">
							<text>{{detail.content}}</text>
						</view>
						<view class="images" v-if="detail.sumbImage && detail.sumbImage[0]" :class="{'single':detail.sumbImage.length == 1, 'two':detail.sumbImage.length == 2, 'overthr':detail.sumbImage.length >= 3}">
							<image v-for="pic in detail.sumbImage" :src="HOSTURL + pic"
							 mode="aspectFill"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="zan" v-if="detail.zan">
			<view class="left">
				<image src="../../static/d4.png" mode=""></image>
				<!-- <image :src="$HOSTURL + item.head_100"></image> -->
				<u-avatar class="image" v-for="(item,index) in detail.zan.slice(0,3)" size="mini" :src="HOSTURL + item.head_100"></u-avatar>
			</view>
			<view class="right">共{{detail.zan.length}}人点赞</view>
		</view>
		<view class="discusslist">
			<view class="detail item" v-for="(item,index) in detail.text">
				<view class="top">
					<view class="avatar">
						<u-avatar size="default" :src="HOSTURL + item.head_100"></u-avatar>
					</view>
					<view class="info">
						<view class="nickname">
							<text>{{item.name}}</text>
						</view>
						<view class="middle">
							{{item.content}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="footer" v-if="detail.userid != $store.state.userid">
			<input type="text" v-model="comments" :adjust-position="false" placeholder-style="font-size:28rpx" placeholder="说点什么">
			<view class="send" @click="comment">
				发送
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				HOSTURL:this.$HOSTURL,
				dy_id: null,
				detail:{},
				cate:[],
				comments:''
			}
		},
		onLoad(option) {
			this.dy_id = option.id
			this.getdetail()
			this.getcate()
		},
		methods: {
			filtercate(id){
				var name
				this.cate.forEach(item=>{
					if(item.id==id){
						return name = item.name
					}
				})
				return name
			},
			async comment(){
				const { data: res } = await this.$Request({
					url:'apis/home/Dymanic/comment',
					data:{
						dy_id: this.dy_id,
						userid: this.$store.state.userid,
						touserid: this.detail.userid,
						type: 0,
						content: this.comments
					}
				})
				if(res.code==200){
					this.comments = ''
					this.getdetail()
					uni.showToast({
						title:'评论成功'
					})
				}
			},
			async getcate(){
				const { data: res } = await this.$Request({
					url:'apis/home/dymanic/category'
				})
				this.cate = res.result
			},
			async getdetail(){
				const { data: res } = await this.$Request({
					url:'apis/Home/Dymanic/dycommentlsts',
					data:{
						dy_id:this.dy_id
					}
				})
				this.detail = res.result
			}
		}
	}
</script>

<style lang="scss" scoped>
	.dydetail {
		height: 100vh;
		background-color: #2A2931;
		.detail {
			background-color: #2A2931;
			margin-bottom: 20rpx;
			padding: 30rpx;
			.top {
				display: flex;
		
				.avatar {
					margin-right: 20rpx;
				}
		
				.info {
					.nickname {
						color: #fff;
						display: flex;
						align-items: center;
						font-size: 28rpx;
						font-weight: bold;
		
						text {
							margin-right: 14rpx;
						}
		
						image {
							width: 72rpx;
							height: 42rpx;
						}
					}
		
					.pubtime {
						color: #757575;
					}
					.middle {
						color: #ddd;
						padding: 10rpx 0;
						position: relative;
						border-radius: 20rpx;
						margin-top: 20rpx;

						.images {
							padding-top: 14rpx;
							display: flex;
							flex-wrap: wrap;
							&.single{
								image {
									width: 40vw;
									height: 40vw;
									border-radius: 12rpx;
								}
							}
							&.overthr{
								image {
									width: 24vw;
									height: 24vw;
									border-radius: 12rpx;
									margin-right: 20rpx;
									margin-bottom: 20rpx;
								}
							}
							&.two{
								image {
									width: 30vw;
									height: 30vw;
									border-radius: 12rpx;
									margin-right: 20rpx;
								}
							}
						}
					}
				}
			}
		
		}
		.discusslist{
			.item{
				margin: 0;
			}
		}
		.zan{
			padding: 10rpx 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;
			.left{
				display: flex;
				align-items: center;
				image{
					width: 40rpx;
					height: 40rpx;
					margin-right: 10rpx;
				}
				.image{
					margin-right: 10rpx;
				}
			}
			.right{
				color:#ccc;
				font-size: 24rpx;
			}
		}
		.footer{
			display: flex;
			height: 120rpx;
			align-items: center;
			justify-content: space-between;
			position: fixed;
			bottom: 0;
			padding: 30rpx 20rpx;
			width: 100%;
			background-color: #1B1A1F;
			input{
				width:68%;
				padding: 8rpx 20rpx;
				background-color: #2A2931;
				border-radius: 10rpx;
				color: #ddd;
			}
			.send{
				background: #673AB7;
				color: #fff;
				border-radius: 5px;
				width: 25%;
				height: 100%;
				line-height: 60rpx;
				text-align: center;
			}
		}
	}
</style>
